<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        window.onload=function(e){
            var username=document.getElementsByClassName('username')[0];
            username.onblur=function(e){
                if(username.Value.length !=4){
                    alert('用户名必须是4个字符才行');
                }

            }
           var password=document.getElementsByClassName('password')[0];

           password.onblur=function(e){
               if(password.Value.length !=4){
                   alert('密码必须是4个字符才行');

               }
           }
            
        }
    </script>
</head>
<body>
    <div class="messge"></div>
    <input type="text" class="username">
</body>
</html>